001    /*
002     * Copyright 2005 Stephen J. McConnell.
003     *
004     * Licensed  under the  Apache License,  Version 2.0  (the "License");
005     * you may not use  this file  except in  compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *   http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed  under the  License is distributed on an "AS IS" BASIS,
012     * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
013     * implied.
014     *
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    
019    package net.dpml.library.info;
020    
021    import net.dpml.lang.ValuedEnum;
022    
023    /**
024     * Enumeration identifying BUILD, RUNTIME and TEST phases.
025     *
026     * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
027     * @version 1.1.0
028     */
029    public final class Scope extends ValuedEnum implements Comparable
030    {
031        static final long serialVersionUID = 1L;
032    
033       /**
034        * Build scope.
035        */
036        public static final Scope BUILD = new Scope( "build", 0 );
037    
038       /**
039        * Runtime scope.
040        */
041        public static final Scope RUNTIME = new Scope( "runtime", 1 );
042    
043       /**
044        * Test scope.
045        */
046        public static final Scope TEST = new Scope( "test", 2 );
047    
048       /**
049        * Array of scope enumeration values.
050        */
051        private static final Scope[] ENUM_VALUES = new Scope[]{BUILD, RUNTIME, TEST};
052    
053       /**
054        * Returns an array of activation enum values.
055        * @return the activation policies array
056        */
057        public static Scope[] values()
058        {
059            return ENUM_VALUES;
060        }
061        
062       /**
063        * Internal constructor.
064        * @param label the enumeration label.
065        * @param index the enumeration index.
066        */
067        private Scope( String label, int index )
068        {
069            super( label, index );
070        }
071        
072       /**
073        * Return a string representation of the scope.
074        * @return the string value
075        */
076        public String toString()
077        {
078            return getName().toUpperCase();
079        }
080        
081       /**
082        * Return a scope value matching the supplied value.
083        * @param value the scope name
084        * @return the scope
085        * @exception IllegalArgumentException if the name if not recognized
086        */
087        public static Scope parse( String value ) throws IllegalArgumentException
088        {
089            if( value.equalsIgnoreCase( "build" ) )
090            {
091                return BUILD;
092            }
093            else if( value.equalsIgnoreCase( "runtime" ) )
094            {
095                return RUNTIME;
096            }
097            else if( value.equalsIgnoreCase( "test" ) )
098            {
099                return TEST;
100            }
101            else
102            {
103                final String error =
104                  "Unrecognized scope argument [" + value + "]";
105                throw new IllegalArgumentException( error );
106            }
107        }
108    }
109